<template>
  <div class="app-container">
    <div class="search-box">
      <div>
        <el-radio-group v-model="searchRadio" size="small" @input="searchFun">
          <el-radio-button label="PGT-A upgarde"></el-radio-button>
          <el-radio-button label="PGTAH"></el-radio-button>
          <el-radio-button label="PGT-SR"></el-radio-button>
          <el-radio-button label="MaReCs"></el-radio-button>
          <el-radio-button label="PGT-M"></el-radio-button>
        </el-radio-group>
      </div>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item>
          <el-input v-model="searchValue" placeholder="送检单位/姓名/送检医生"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="info"
                   plain
                   icon="el-icon-upload2"
                   size="mini"
                   @click="handleImport"
                   v-hasPermi="['system:warning:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:warning:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:warning:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="warningList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" sortable></el-table-column>
      <el-table-column label="项目类型" align="center" prop="itemType" />
      <el-table-column label="送检单位名称" align="center" prop="sjdwName" />
      <el-table-column label="送检码" align="center" prop="sampleBoxCode" />
      <el-table-column label="英文简称" align="center" prop="sampleDecWay" />
      <el-table-column label="家系类型" align="center" prop="twoJxType">
        <template slot-scope="scope">
          <span v-if="scope.row.twoJxTypeFlag && scope.row.twoJxTypeFlag === 1" style="color: #f56c6c">{{scope.row.twoJxType}}</span>
          <span v-else>{{scope.row.twoJxType}}</span>
        </template>
      </el-table-column>
      <el-table-column label="病例ID" align="center" prop="caseId" />
      <el-table-column label="受检人姓名" align="center" prop="patientName" />
      <el-table-column label="受检人年龄" align="center" prop="patientAge" />
      <el-table-column label="受检人核型" align="center" prop="patientKaryotype" />
      <el-table-column label="配偶年龄" align="center" prop="mateAge" />
      <el-table-column label="配偶核型" align="center" prop="mateKaryotype" />
      <el-table-column label="临床指证" align="center" prop="clinicalIndication" />
      <el-table-column label="受精方式" align="center" prop="sjfs" />
      <el-table-column label="形态学评级" align="center" prop="sampleLevel" />
      <el-table-column label="样本编号" align="center" prop="sampleId" />
      <el-table-column label="样本类型" align="center" prop="sampleType" />
      <el-table-column label="扩增方法" align="center" prop="kzMethod"/>
      <el-table-column label="建库方法" align="center" prop="jkMethod"/>
      <el-table-column label="WGA扩增试剂盒货号" align="center" prop="wgaItemNo" />
      <el-table-column label="WGA扩增试剂盒批号" align="center" prop="wgaBatchNo" />
      <el-table-column label="检测浓度" align="center" prop="checkNd">
        <template slot-scope="scope">
          <span v-if="scope.row.checkNdFlag && scope.row.checkNdFlag === 1" style="color: #f56c6c">{{scope.row.checkNd}}</span>
          <span v-else>{{scope.row.checkNd}}</span>
        </template>
      </el-table-column>
      <el-table-column label="CNV试剂盒名称" align="center" prop="cnvKitName" />
      <el-table-column label="CNV试剂盒批次" align="center" prop="cnvKitLot" />
      <el-table-column label="建库文库浓度" align="center" prop="jkwkNd">
        <template slot-scope="scope">
          <span v-if="scope.row.jkwkNdFlag && scope.row.jkwkNdFlag === 1" style="color: #f56c6c">{{scope.row.jkwkNd}}</span>
          <span v-else>{{scope.row.jkwkNd}}</span>
        </template>
      </el-table-column>
      <el-table-column label="送检单样本名称" align="center" prop="sampleName" />
      <el-table-column label="raw_reads" align="center" prop="rawReads" />
      <el-table-column label="high_quality_rate(%)" align="center" prop="highQualityRate" />
      <el-table-column label="mapping_rate(%)" align="center" prop="mappingRate" />
      <el-table-column label="duplication_rate(%)" align="center" prop="duplicationRate" />
      <el-table-column label="valid_reads" align="center" prop="validReads" />
      <el-table-column label="valid_reads_GC_content(%)" align="center" prop="validReadsGcContent" />
      <el-table-column label="valid_reads_rate(%)" align="center" prop="validReadsRate" />
      <el-table-column label="CV(1000K_bin_size)" align="center" prop="cv" />
      <el-table-column label="data_QC_conclusion" align="center" prop="dataQcConclusion">
        <template slot-scope="scope">
          <span v-if="scope.row.dataQCconclusionFlag && scope.row.dataQCconclusionFlag === 1" style="color: #f56c6c">{{scope.row.dataQcConclusion}}</span>
          <span v-else style="color: #00ff80">{{scope.row.dataQcConclusion}}</span>
        </template>
      </el-table-column>
      <el-table-column label="性染色体核型" align="center" prop="sexChromKaryotype" />
      <el-table-column label="CNV检测结果" align="center" prop="cnvResult" />
      <el-table-column label="结果解释" align="center" prop="resultExplain" />
      <el-table-column label="提示CNV" align="center" prop="remindCnv" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:warning:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:warning:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title"
               :visible.sync="upload.open"
               width="400px"
               append-to-body>
      <el-upload ref="upload"
                 :limit="1"
                 accept=".xlsx, .xls"
                 :headers="upload.headers"
                 :action="upload.url"
                 :disabled="upload.isUploading"
                 :on-progress="handleFileUploadProgress"
                 :on-success="handleFileSuccess"
                 :auto-upload="false"
                 drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center"
             slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>

        </div>
      </el-upload>
      <div slot="footer"
           class="dialog-footer">
        <el-button type="primary"
                   @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listWarning, getWarning, delWarning, addWarning, updateWarning } from "@/api/system/warning";
  import { getToken } from '@/utils/auth'

  export default {
    name: "Warning",
    data() {
      return {
        fileList: [],
        searchValue: "",
        searchRadio: "PGT-A upgarde",
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 样本表格数据
        warningList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据

          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/system/warning/importData"
        },
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          sampleDecWay:"PGTA"
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
       this.getList();
    },
    methods: {
      /** 导入按钮操作 */
      handleImport () {
        this.upload.title = "本地化预警导入";
        this.upload.open = true;
      },

      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
      },
      // 单选检索
      searchFun(val) {
        var sampleDecWay = "";
        if(val == "PGT-A upgarde"){
          sampleDecWay = "PGTA"
        }else if(val == "PGTAH"){
          sampleDecWay = "PGTAH"
        }else if(val == "PGT-SR"){
          sampleDecWay = "PGTSR"
        }else if(val == "MaReCs"){
          sampleDecWay = "MaReCs"
        }else if(val == "PGT-M"){
          sampleDecWay = "PGTM"
        }
        this.queryParams.sampleDecWay = sampleDecWay;
        this.getList();
      },
      /** 查询样本列表 */
      getList() {
        this.loading = true;
        listWarning(this.queryParams).then(response => {
          this.warningList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          isDelete: null,
          id: null,
          itemType: null,
          sjdwName: null,
          caseId: null,
          patientName: null,
          patientAge: null,
          patientKaryotype: null,
          mateAge: null,
          mateKaryotype: null,
          clinicalIndication: null,
          sjfs: null,
          sampleLevel: null,
          sampleId: null,
          sampleType: null,
          kzMethod: null,
          jkMethod: null,
          wgaItemNo: null,
          wgaBatchNo: null,
          checkNd: null,
          cnvKitName: null,
          cnvKitLot: null,
          jkwkNd: null,
          sampleName: null,
          rawReads: null,
          highQualityRate: null,
          mappingRate: null,
          duplicationRate: null,
          validReads: null,
          validReadsGcContent: null,
          validReadsRate: null,
          cv: null,
          dataQcConclusion: null,
          sexChromKaryotype: null,
          cnvResult: null,
          resultExplain: null,
          remindCnv: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.queryParams.searchValue = this.searchValue;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.searchValue = undefined;
        this.searchValue = undefined;
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },

      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除样本编号为"' + ids + '"的数据项？').then(function() {
          return delWarning(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/warning/export', {
          ...this.queryParams
        }, `warning_${new Date().getTime()}.xlsx`)
      },

      // 文件上传中处理
      handleFileUploadProgress (event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess (response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileForm () {
        this.$refs.upload.submit();
      }


    }
  };
</script>


<style lang="scss">
.search-box {
  display: flex;
  justify-content: space-between;
}
.el-table .warning-row {
  color: #f56c6c;
}
</style>
